/**
 * Copyright (c) 2008 Trent Hoeppner
 * 
 * This file is part of BillCalc.
 * 
 * BillCalc is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * BillCalc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with BillCalc.  If not, see <http://www.gnu.org/licenses/>.
 **/

package com.trentech.billcalc.gui;

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * Messages is a class for accessing bundle data in a Locale-independent manner
 * for the com.trentech.billcalc.gui package.
 * 
 * @author Trent Hoeppner
 */
public class Messages {

    /**
     * The name of the bundle that contains the resources.
     */
    private static final String BUNDLE_NAME = "com.trentech.billcalc.gui.messages";


    /**
     * The bundle used to access the resources in the default Locale.
     */
    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);


    /**
     * Constructor for Messages.
     */
    private Messages() {
        // do nothing
    }


    /**
     * Returns the resource for the given key in the default Locale.
     * 
     * @param   key the key to identify the resource.  Cannot be null or empty.
     * 
     * @return  the resource for the key in the default Locale.
     */
    public static String getString(String key) {
        try {
            return RESOURCE_BUNDLE.getString(key);
        }
        catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }
    
    
    /**
     * Obtains a compound string for the given key, and inserts the given 
     * arguments.
     * 
     * @param   key     the key to the resource in the bundle.  Cannot be null 
     *                  or empty.
     * @param   args    the arguments to fill in for the compound resource.  
     *                  Must have at least one argument.
     *                  
     * @return  the compound string.  Will not be null or empty. 
     */
    public static String getCompoundString(String key, Object ... args) {
        MessageFormat format = new MessageFormat(getString(key));
        return format.format(args);
    }
    
    
    /**
     * Returns the compound string for the unpaid estimate for the given Biller.
     * 
     * @param   billerName  the name of the Biller the estimate is for.  Cannot
     *                      be null or empty.
     *                      
     * @return  the compound with the Biller name.  Will not be null or empty.
     */
    public static String getUnpaidEstimate(String billerName) {
        return getCompoundString("BillCalcFrame.unpaidEstimate", billerName);
    }
    
    
    /**
     * Returns the compound string to show a Resident who owes a list of debts.
     * 
     * @param   residentName    the name of the Resident.  Cannot be null or 
     *                          empty.
     *                          
     * @return  the compound string with the Resident's name.  Will not be null 
     *          or empty.
     */
    public static String getWhoOwesTheFollowing(String residentName) {
        return getCompoundString("BillCalcFrame.whoOwesTheFollowing", residentName);
    }
    
    
    /**
     * Returns the compound string to show a Resident who owes another 
     * Resident.
     * 
     * @param   ower        the name of the Resident who owes the money.  
     *                      Cannot be null or empty.
     * @param   owedPerson  the name of the Resident who is owed the money.
     *                      Cannot be null or empty.
     *                      
     * @return  the compound string stating that the first Resident owes the 
     *          second Resident.  Will not be null or empty.
     */
    public static String getWhoOwesWho(String ower, String owedPerson) {
        return getCompoundString("BillCalcFrame.whoOwesWho", ower, owedPerson);
    }
}
